#include <iostream>
#include <vector>

#include "UdpServer.hpp"

// 打印使用说明
void Usage(std::string proc) {
  std::cout << "\n\tUsage: " << proc << " port[1024+]\n" << std::endl;
}

// 回声处理函数
std::string EchoHandler(const std::string& datastr, const std::string& clientip,
                        uint16_t clientport) {
  std::string echo_string =
      "[" + clientip + ":" + std::to_string(clientport) + " echo]# " + datastr;
  return echo_string;
}

int main(int argc, char* argv[]) {
  if (argc != 2) {
    Usage(argv[0]);
    exit(0);
  }

  // 创建并初始化UDP服务器
  std::unique_ptr<UdpServer> svr(new UdpServer(std::stoi(argv[1])));
  svr->Init();

  // 运行服务器
  svr->Run(EchoHandler);
  return 0;
}
